﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 抓人游戏
{
    public partial class Form1 : Form
    {
        Random r;

        public Form1()
        {
            InitializeComponent();
            r = new Random();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label1.Visible = !label1.Visible;
            //label1.Location.X = r.Next(this.ClientRectangle.Width);
            //label1.Location.Y = r.Next(this.ClientRectangle.Height);
            int width = this.ClientRectangle.Width - label1.Width;
            int height = this.ClientRectangle.Height - label1.Height;
            label1.Left = r.Next(width);
            label1.Top = r.Next(height);
        
        }

        private void label1_Click(object sender, EventArgs e)
        {
            if(label1.Visible == true)
            {
                timer1.Enabled = false;
                label1.Text = "被你抓到了";
                button1.Text = "开始游戏";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(timer1.Enabled == false)
            {
                button1.Text = "结束游戏";
                label1.Enabled = true;
                label1.Text = "张三";
                timer1.Enabled = true;
            }
            else
            {
                button1.Text = "开始游戏";
                timer1.Enabled = false;
                label1.Enabled = false;
            }
        }
    }
}
